//
//  ZJDesThirdTravelCollectionViewCell.m
//  BreadTravel
//
//  Created by 张健 on 15/12/24.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "ZJDesThirdTravelCollectionViewCell.h"
#import "ZJDesThirdTravelModel.h"
#import "ZJDesThirdTravelTableViewCell.h"
@interface ZJDesThirdTravelCollectionViewCell ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,retain)UITableView *myTableView;
@property(nonatomic,retain)NSMutableArray *allArray;

@end
@implementation ZJDesThirdTravelCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self createView];
    }
    return self;
}

- (void)createView{
    
    
    
    self.myTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, WIDTH, HEIGHT-130) style:UITableViewStylePlain];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.rowHeight = 125;
    [self.contentView addSubview:self.myTableView];
    [self.myTableView registerClass:[ZJDesThirdTravelTableViewCell class] forCellReuseIdentifier:@"ZJDesThirdTravelTableViewCell"];
    self.autoresizesSubviews = NO;

    
    self.allArray = [NSMutableArray array];
    
}

-(void)setParamete:(NSString *)paramete{

    
    self.allArray = [NSMutableArray new];
    [self.myTableView reloadData];
    MBProgressHUD *hub = [MBProgressHUD showHUDAddedTo:self.myTableView animated:YES];
    [hub show:YES];
    hub.labelText = @"加载中";
    NSString *url = [NSString stringWithFormat:@"http://api.breadtrip.com/destination/place/%@/%@/pois/%@/?start=0&count=20&sort=default&shift=false&latitude=38.882364559096146&longitude=121.53947115009305", self.type, self.id,self.title];
//    NSString *url = [NSString stringWithFormat:@"http://api.breadtrip.com/destination/place/2/4648/pois/all/?start=0&count=20&sort=default&shift=false&latitude=38.882364559096146&longitude=121.53947115009305"];
    [AFNetworkTool getUrl:url body:nil result:HXJSON headerFile:nil success:^(id result) {
        
        self.allArray = [NSMutableArray new];
        
        NSMutableArray *array = result[@"items"];
        for (NSMutableDictionary *dic in array) {
            ZJDesThirdTravelModel *placeModel = [ZJDesThirdTravelModel modelWithDictionary:dic];
            
            if ([[dic objectForKey:@"recommended_reason"]isEqual:@""]) {
                
                NSString *description1 = [dic objectForKey:@"description"];
                placeModel.description1 = description1;
            }
            [self.allArray addObject:placeModel];
        }
        [self.myTableView reloadData];
        [hub hide:YES];
        
    } failure:^(NSError *error) {
        
        
    }];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellID = @"ZJDesThirdTravelTableViewCell";
    ZJDesThirdTravelTableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    if (cell == nil) {
        cell = [[ZJDesThirdTravelTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    cell.placeModel = [self.allArray objectAtIndex:indexPath.row];
    
    return cell;
}

//点击cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    // 取消cell的置灰效果
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.allArray.count;
}


@end
